﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;
using BusinessLogicLayer;
using DataAccessLayer;
//using DataAccessLayer.Reports;

namespace PresentationLayer
{
    public partial class GenerateReport : System.Web.UI.Page
    {
        //GenerateReportController generateRptController = new GenerateReportController();

        protected void Page_Load(object sender, EventArgs e)
        {
            //CRDeptWithPrice cRpt = new CRDeptWithPrice();
            //IList eLst = generateRptController.empList();
            //if (eLst != null)
            //{
            //    cRpt.SetDataSource(eLst);
            //    rpt.ReportSource = cRpt;
            //    rpt.DataBind();
            //    rpt.RefreshReport();

            //}
            if (!IsPostBack)
            {
                bindYear(ddlYear1);
                bindYear(ddlYear2);
                bindYear(ddlYear3);

                bindMonth(ddlMonth1);
                bindMonth(ddlMonth2);
                bindMonth(ddlMonth3);

                ddlMonth2.Enabled = false;
                ddlMonth3.Enabled = false;
                ddlYear2.Enabled = false;
                ddlYear3.Enabled = false;
            }
        }

        private void bindMonth(DropDownList ddlM)
        {
            ddlM.Items.Clear();
            ListItem lt = new ListItem();
            for (int i = 1; i <= 12; i++)
            {
                lt = new ListItem();
                lt.Text = Convert.ToDateTime(i.ToString() + "/1/1900").ToString("MMMM");
                lt.Value = i.ToString();
                ddlM.Items.Add(lt);
            }
            ddlM.Items.FindByValue(DateTime.Now.Month.ToString()).Selected = true;
        }

        private void bindYear(DropDownList ddl)
        {
            ddl.Items.Clear();
            ListItem lt = new ListItem();

            for (int i = DateTime.Now.Year; i >= 1950; i--)
            {
                lt = new ListItem();
                lt.Text = i.ToString();
                lt.Value = i.ToString();
                ddl.Items.Add(lt);
            }
            ddl.Items.FindByValue(DateTime.Now.Year.ToString()).Selected = true;
        }

        protected void ddlNumOfMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlNumOfMonth.SelectedValue == "3")
            {
                ddlMonth2.Enabled = true;
                ddlMonth3.Enabled = true;
                ddlYear2.Enabled = true;
                ddlYear3.Enabled = true;
            }
            else if (ddlNumOfMonth.SelectedValue == "2")
            {
                ddlMonth2.Enabled = true;
                ddlMonth3.Enabled = false;
                ddlYear2.Enabled = true;
                ddlYear3.Enabled = false;
            }
            else
            {
                ddlMonth2.Enabled = false;
                ddlMonth3.Enabled = false;
                ddlYear2.Enabled = false;
                ddlYear3.Enabled = false;
            }
        }

        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            //CrystalReport1 c = new CrystalReport1();
            //CRDeptWithPrice cRpt = new CRDeptWithPrice();
            //IList eLst = generateRptController.empList();
            //if (eLst != null)
            //{
            //    cRpt.SetDataSource(eLst);
            //    rpt.ReportSource = cRpt;
            //    rpt.DataBind();
            //    rpt.RefreshReport();

            //}
            

        }
    }
}